package com.heima.wemedia;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.junit.jupiter.api.Test;

import java.io.IOException;

/**
 * @author huan
 * @serial 每天一百行, 致敬未来的自己
 * @Description
 */

public class ReptilesDemo {
    @Test
    public void test() throws IOException {
        Document document = Jsoup.connect("https://3g.163.com/touch/news/sub/history/?ver=c&clickfrom=index2018_header_main")
                .header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36")
                .get();
        Elements articles = document.getElementsByTag("article");
        for (Element article : articles) {
            Element element = article.getElementsByTag("a").get(0);
            String href = element.attr("href");
            System.out.println("文章详情 = " + href);
            Element title = element.getElementsByClass("title").get(0);
            String text = title.text();
            System.out.println("文章标题 = " + text);
        }
    }
}
